{extend name='public/base' /}

{block name="content"}

<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">
                    <div class="layui-inline">
                        <label class="layui-form-label">商户：</label>
                        <div class="layui-input-inline">
                            <select name="merchant_id" lay-verify="required" lay-search="">
                                <option value="0" ></option>
                                {volist name="merchant_list" id="t"}
                                {if empty($t.name)||$t.name=='-'}
                                <option value="{$t.id}" >{$t.company} - {$t.code}-{$t.biz_state}-{$t.positions_code}</option>
                                {else/}
                                <option value="{$t.id}" >{$t.name} - {$t.code}-{$t.biz_state}-{$t.positions_code}</option>
                                {/if}
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn layui-btn-sm" data-id="table_id" lay-filter="search"
                                lay-submit="">
                            <i class="layui-icon" ></i>搜索
                        </button>
                        <button type="reset" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i
                                class="layui-icon layui-icon-refresh"></i>{:__('Reset')}
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>


    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table_id" lay-filter="table_id"></table>
        </div>
    </div>

</div>
{/block}

{block name="js"} <!--js处理区-->


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <!-- <button type="button" lay-event="add" class="layui-btn {:node('Admin/addAdmin')} layui-btn-sm">添加安保人员</button>
        <button type="button" lay-event="del" class="layui-btn {:node('Admin/del')} layui-btn-sm layui-btn-danger">
            删除安保人员
        </button> -->
        <button type="button" lay-event="reload" class="layui-btn  layui-btn-sm  layui-btn-primary">刷新表格</button>
    </div>
</script>
<script type="text/html" id="operationTpl">
    <a href="javascript:;" class="layui-btn  layui-btn-primary layui-btn-xs {:node('Cost/adminEdit')}" data-title="查看详情" lay-event="adminEdit"><i class="layui-icon">&#xe705;</i></a>
    <a href="javascript:;" class="layui-btn   layui-btn-xs {:node('common/costPrint')}" data-title="打印" lay-event="print"><i class="layui-icon">&#xe66d;</i></a>
</script>

<script>
    layui.use(['element', 'table', 'form', 'jquery', 'lucky','opTable','laydate',], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky=layui.lucky;
        var opTable = layui.opTable;
        var laydate = layui.laydate;
        form.render();
        laydate.render({
            elem: '#settlement_time'
            ,type: 'month',
            trigger: 'click'
        });
        var myTables = table.render({
            elem: '#table_id',
            url:"{:url('index')}",
            where: { info_type: 2},
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter'],
            // defaultToolbar: ['filter', 'exports', 'print'],
            even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:20
                ,limits:[10,20,30,50]
            },
            // height: 'full-100',100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                { title: '', type: 'checkbox', fixed: true},


                { title: '品牌名',width:100, field: 'merchant_user',templet:function (item) {
                        // +'('+item.merchant.mobile+')'
                        return item.merchant.name;
                    }, fixed:'left'},
                { title: '签约租户', width:200,field: 'merchant',templet:function (item) { return item.merchant.company}},
                {title: '合同号', field: 'merchant',width:200, templet: function (item) {
                        return item.merchant.code
                    }
                },
                { title: '缴费单编号', field: 'order_sn', edit: 'text',width:150},
                {title: '费用项名称', field: 'merchant',width:200, templet: function (item) {
                        return item.costType.cost_name
                    }
                },

                { title: '退费金额(元)',width: 90, field: 'all_amount',templet:function (item) { return item.all_amount/100} },
                {
                    title: '缴费区间', field: 'create_time', width: 250, templet: function (item) {
                        if (item.start_time) {
                            return layui.util.toDateString((item.start_time) * 1000, 'yyyy-MM-dd') + '~' + layui.util.toDateString((item.end_time) * 1000, 'yyyy-MM-dd');
                        } else {
                            return '';
                        }
                    }
                },
                { title: '缴费状态', field: 'pay_status',templet:function (item) {
                        return '已退费';
                    }},
                {templet: '#operationTpl', width: 200,align: 'center', title: '操作',fixed:'right'}
            ]],
            //  展开的列配置
            openCols: [
                {field: 'desc', title: '描述信息'}
            ],
            done: function (res) {
                layer.closeAll('loading');
            }
        });
//导出事件
        $('#export').on('click',function () {
            var merchant_id = $('#merchant_id').val() ;
            var contract_code = $('#contract_code').val() ;
            var pointId = $('#pointId').val() ;
            var pay_status = $('#pay_status').val() ;
            var cost_type_id = $('#cost_type_id').val() ;
            var order_sn = $('#order_sn').val() ;
            var url = "{:url('export')}"+'?pay_status='+pay_status + "&export=" + 1+ "&merchant_id=" + merchant_id+ "&contract_code=" + contract_code+"&cost_type_id=" + cost_type_id+"&order_sn=" + order_sn;
            window.open(url);
        });

        //导出时阻止页面刷新
        $(".layui-form").submit(function (e) {
            e.preventDefault();
        })

        /**
         * 监听单行工具操作
         */
        table.on('tool(table_id)', function (obj) {
            var data = obj.data;
            var _id=parseInt(data.id);
            var layEvent = obj.event;
            if(layEvent==="adminEdit"){
                lucky.CreateOpenForm("编辑","{:url('common/adminEdit')}?id=" + _id);
                return false;
            }else if(layEvent==="print"){
                lucky.CreateOpenForm("打印","{:url('common/costPrint')}?id=" + _id,'85%');
                return false;
            }
        });
        table.on('toolbar(table_id)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if(obj.event==="reload"){
                lucky.CreateReload();
            }
        });

        /**
         * 关键词搜索树
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch(obj.field);
            return false;
        });
    });

</script >

{/block}
